#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,k,a[N],ans;
map<int,int> mp,cnt;
signed main() {
	freopen("reporter.in","r",stdin);
	freopen("reporter.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		mp.clear();cnt.clear();
		for(int j=i;j<=n;j++){
			--cnt[mp[a[j]]];
			++mp[a[j]];
			++cnt[mp[a[j]]];
			if(k==1){
				if(cnt[1]) ++ans;
			}
			if(k==2){
				if(cnt[1]&&cnt[2]) ++ans;
			}
			if(k==3){
				if(cnt[1]&&cnt[2]&&cnt[3]) ++ans;
			}
			if(k==4){
				if(cnt[1]&&cnt[2]&&cnt[3]&&cnt[4]) ++ans;
			}
		}
	}
	cout<<ans;
	return 0;
}
